package com.company.project.controller.ldjsc.wzsj;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.company.project.entity.ldjsc.szjt.JscSzjtZfgjjEntity;
import com.company.project.entity.ldjsc.wzsj.JscwzTemplateExplainEntity;
import com.company.project.service.ldjsc.wzsj.JscwzTemplateExplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.company.project.common.utils.DataResult;




/**
 * 数据解读
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2025-08-20 14:16:51
 */
@Controller
@RequestMapping("/sxzy")
public class JscwzTemplateExplainController {
    @Autowired
    private JscwzTemplateExplainService jscwzTemplateExplainService;


    @ApiOperation(value = "数据解读_详情1")
    @GetMapping("/jsc-dd-zt/getJscwzExplain-xq2")
    @ResponseBody
    public DataResult getJscwzExplainXq2(JscwzTemplateExplainEntity jscwzTemplateExplain){
        LambdaQueryWrapper<JscwzTemplateExplainEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(JscwzTemplateExplainEntity::getId, jscwzTemplateExplain.getId());
        queryWrapper.orderByDesc(JscwzTemplateExplainEntity::getId);

        if (jscwzTemplateExplain.getMidgard_offset() != null){
            jscwzTemplateExplain.setMidgard_page(1);
        }
        IPage<JscwzTemplateExplainEntity> iPage = jscwzTemplateExplainService.page(jscwzTemplateExplain.getQueryPage(), queryWrapper);
        List<JscwzTemplateExplainEntity> records = iPage.getRecords();


        // 构造所需的数据结构
        List<String> columnNames = Arrays.asList(
                "id",
                "tag",
                "title",
                "detail",
                "data_time",
                "index_no",
                "source",
                "depart",
                "update_time"
        );

        Map<String, Object> result = new HashMap<>();
        result.put("columnNames", columnNames);
        result.put("value", records);

        return DataResult.success(result);
    }


    @ApiOperation(value = "数据解读_列表")
    @GetMapping("/jsc-dd-zt/getJscwzExplain-lb2")
    @ResponseBody
    public DataResult getJscwzExplainLb2(JscwzTemplateExplainEntity jscwzTemplateExplain){
        LambdaQueryWrapper<JscwzTemplateExplainEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(JscwzTemplateExplainEntity::getTag, jscwzTemplateExplain.getTag());
        queryWrapper.orderByDesc(JscwzTemplateExplainEntity::getData_time);

        if (jscwzTemplateExplain.getMidgard_offset() != null){
            jscwzTemplateExplain.setMidgard_page(1);
        }
        IPage<JscwzTemplateExplainEntity> iPage = jscwzTemplateExplainService.page(jscwzTemplateExplain.getQueryPage(), queryWrapper);
        List<JscwzTemplateExplainEntity> records = iPage.getRecords();


        // 构造所需的数据结构
        List<String> columnNames = Arrays.asList(
                "id",
                "tag",
                "title",
                "detail",
                "data_time",
                "index_no",
                "source",
                "depart",
                "update_time"
        );

        Map<String, Object> result = new HashMap<>();
        result.put("columnNames", columnNames);
        result.put("value", records);

        return DataResult.success(result);
    }

    @ApiOperation(value = "数据解读_详情2")
    @GetMapping("/jsc-dd-zt/getJscwzExplain-lbpx2")
    @ResponseBody
    public DataResult getJscwzExplainLbpx2(JscwzTemplateExplainEntity jscwzTemplateExplain){
        LambdaQueryWrapper<JscwzTemplateExplainEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(JscwzTemplateExplainEntity::getTag, jscwzTemplateExplain.getTag());
        queryWrapper.eq(JscwzTemplateExplainEntity::getIndex_no, jscwzTemplateExplain.getIndex_no());
        queryWrapper.orderByDesc(JscwzTemplateExplainEntity::getData_time);

        if (jscwzTemplateExplain.getMidgard_offset() != null){
            jscwzTemplateExplain.setMidgard_page(1);
        }
        IPage<JscwzTemplateExplainEntity> iPage = jscwzTemplateExplainService.page(jscwzTemplateExplain.getQueryPage(), queryWrapper);
        List<JscwzTemplateExplainEntity> records = iPage.getRecords();


        // 构造所需的数据结构
        List<String> columnNames = Arrays.asList(
                "id",
                "tag",
                "title",
                "detail",
                "data_time",
                "index_no",
                "source",
                "depart",
                "update_time"
        );

        Map<String, Object> result = new HashMap<>();
        result.put("columnNames", columnNames);
        result.put("value", records);

        return DataResult.success(result);
    }

}
